<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue3的none-props</title>
  <style>
    .section {
      margin-top: 30px;
    }
  </style>
</head>
<body>
  <div id="app"></div>
  <script src="https://unpkg.com/vue@next"></script>
  <script>    
    const app = Vue.createApp({
      template: `
        <div>
          <div class="section">
            <comp msg="消息1" style="color: red" />
          </div>
          <div class="section">
            <comp1 msg="消息asfaf" style="color: green" />
          </div>
          <div class="section">
            <comp2 msg="多个根元素的组件Fragment" style="color: blue" />
          </div>
          <div class="section">
            <comp-event data-msg="来自父组件的数据" style="color: yellow" />
          </div>
        </div>
      `
    })

    app.component('Comp', {
      template: `
        <div>
          只有单根组件的情况下，msg会自动挂在根元素上
          $attrs: {{JSON.stringify($attrs)}}
        </div>
      `
    })

    app.component('Comp1', {
      inheritAttrs: false,
      template: `
        <div>
          情形2：设置inheritAttrs:false[禁用继承]情况下
          <div v-bind="$attrs">none props属性都被挂在我身上了</div>
          $attrs: {{JSON.stringify($attrs)}}
        </div>
      `
    })

    app.component('Comp2', {
      template: `
        <div>
          情形3：多个根组件
        </div>
        <div v-bind="$attrs">none props属性都被挂在我身上了</div>
      `
    })

    app.component('CompEvent', {
      template: `
        <div>
          情形4：事件监听器
        </div>
      `,
      created () {
        console.log(this.$attrs)
      }
    })

    app.mount('#app')
  </script>
</body>
</html>